package com.neuedu.mblog.dao;

import com.neuedu.mblog.entiry.Disease;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * 项目：his
 * 创建时间：  2021/12/17   9:21
 * 作者 :jshand
 * 描述 : 疾病表的数据库访问层
 */
public class DiseaseDao extends BaseDao<Disease> {


    /***
     * 根据sql分页查询
     * @param sql  查询数据的sql
     * @param params  sql里面的参数
     * @return
     *
     * SELECT id,  disease_code,  disease_name, disease_icd, cate_id, createtime, valid FROM disease  wehre name like ??? limt
     *
     * select * from (
     *
     * )  limit
     */
    public List<Disease> selectListByPage(String sql, Object[] params ) throws SQLException, ClassNotFoundException {
        Connection con = super.getConnection();

        PreparedStatement stmt = con.prepareStatement(sql);

        //绑定变量
        if(params!=null && params.length>0){
            for (int i = 1; i <= params.length; i++) {
                stmt.setObject(i,params[i-1]);
            }
        }
        ResultSet rs = stmt.executeQuery();

        List list = new ArrayList();
        Disease disease = null;
        while (rs.next()){
            disease = new Disease();
            disease.setId(rs.getInt("id"));
            disease.setDiseaseCode(rs.getString("disease_code"));
            disease.setDiseaseName(rs.getString("disease_name"));
            disease.setDiseaseIcd(rs.getString("disease_icd"));
            disease.setCateId(rs.getInt("cate_id"));
            disease.setCreatetime(rs.getTimestamp("createtime"));
            disease.setValid(rs.getString("disease_code"));
            list.add(disease);
        }
        //关闭资源
        close(con,stmt,rs);

        return list;
    }




    /**
     * 增删改查的方法 此处不写了，
     * @param sql
     * @return
     */

    @Override
    public List<Disease> selectList(String sql) {
        return null;
    }

    @Override
    public List<Disease> selectList(String sql, Object... params) throws Exception {
        return null;
    }

    @Override
    public <E> E selectById(Integer id) {
        return null;
    }

    @Override
    public int save(Disease disease) {
        return 0;
    }

    @Override
    public int update(Disease disease) {
        return 0;
    }

    @Override
    public int delete(Integer id) {
        return 0;
    }
}
